package book.action;

import static common.utils.Constants.LIMIT;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import service.impl.BookReviewServiceImpl;

import common.action.BaseAction;
import common.pojo.BookReview;
import common.utils.Constants;
import common.utils.Page;
import common.utils.PageUtil;
import common.utils.PaginationUtil;
import common.utils.SessionUtils;

@Scope("prototype")
@Controller(value = "bookReview")
public class BookReviewAction extends BaseAction {

	
	/**
	 * 获取列表
	 * 
	 * @return
	 * @throws Exception
	 */
	public String getBookReviewListByPage() throws Exception {
		String currentTmp = request.getParameter("current");//获取页码参数
		String bookId = request.getParameter("bookId");//获取书id
		BookReview bookReview = new BookReview();
		bookReview.setDeleted(Constants.NOT_DELETED);
		bookReview.setBookId(Integer.parseInt(bookId));
		int total= bReviewService.queryByCount(bookReview);//查询符合条件的类型数量
		bookReview.setReviewState(1);//好评
		int goodtotal= bReviewService.queryByCount(bookReview);
		int current = PageUtil.getCurrent(currentTmp);//判断当前页码数
		Page page = PageUtil.createPage(LIMIT, total, current);//生成页码实体参数
		brlist = bReviewService.find(page.getBeginIndex(), LIMIT);//根据页码参数以及每页显示数量获取列表
		pagination = PaginationUtil.getPaginationStyleTwo(page,
				"getBookReviewListByPage.action?bookId="+bookId,"");//页码显示的静态代码，字符串，很长
		request.setAttribute("goodtotal", goodtotal);
		request.setAttribute("badtotal", total-goodtotal);
		return "reviewList";
	}


	/**
	 * 删除类型
	 */
	public String deleteById() {
		String ids = request.getParameter("ids");
		bReviewService.delete(ids,SessionUtils.getAdminName(request));
		return SUCCESS;
	}


	private static final long serialVersionUID = 1L;

	//引用service层
	@Resource
	private BookReviewServiceImpl bReviewService;
	private BookReview bReview;
	private List<BookReview> brlist;//列表
	private String pagination;//分页
	private String dofunction;//返回处理刷新

	
	


	public BookReview getbReview() {
		return bReview;
	}


	public void setbReview(BookReview bReview) {
		this.bReview = bReview;
	}


	public List<BookReview> getBrlist() {
		return brlist;
	}


	public void setBrlist(List<BookReview> brlist) {
		this.brlist = brlist;
	}


	public String getDofunction() {
		return dofunction;
	}

	public void setDofunction(String dofunction) {
		this.dofunction = dofunction;
	}

	public String getPagination() {
		return pagination;
	}

	public void setPagination(String pagination) {
		this.pagination = pagination;
	}



}
